<template>
  <Header />
  <div class="registry">
    <h2 class="title">欢迎注册智能云工厂系统</h2>
    <el-form
      :model="registerForm"
      :rules="rules"
      ref="registerForm"
      label-width="100px"
      class="registerForm"
    >
      <el-form-item label="账号" prop="account">
        <el-input v-model="registerForm.account"></el-input>
      </el-form-item>
      <el-form-item label="密码" prop="password">
        <el-input v-model="registerForm.password"></el-input>
      </el-form-item>
      <el-form-item label="真实姓名" prop="name">
        <el-input v-model="registerForm.name"></el-input>
      </el-form-item>
      <el-form-item label="联系电话" prop="phone">
        <el-input v-model="registerForm.phone"></el-input>
      </el-form-item>
      <el-form-item label="注册类型" prop="character">
        <el-radio-group v-model="registerForm.character">
          <el-radio label="云工厂管理员"></el-radio>
          <el-radio label="经销商"></el-radio>
        </el-radio-group>
      </el-form-item>
      <el-form-item
        label="工厂名称"
        prop="factoryName"
        v-if="registerForm.character == '云工厂管理员'"
      >
        <el-input v-model="registerForm.factoryName"></el-input>
      </el-form-item>
      <el-form-item
        label="工厂简介"
        prop="factoryDetail"
        v-if="registerForm.character == '云工厂管理员'"
      >
        <el-input v-model="registerForm.detail"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button class="registerBtn" type="primary" @click="submitForm()">
          <span style="color: black; font-size: 16px">去注册!</span>
        </el-button>
        <el-button @click="resetForm('registerForm')">重置</el-button>
      </el-form-item>
    </el-form>
  </div>
  <div class="footer">
    <p class="footerText">©2021 cloudfactory.com neu认证 20195682 号</p>
  </div>
</template>

<script>
import Header from '../components/pageHeader.vue'
import { ElMessage } from 'element-plus'
import axios from 'axios'
export default {
  components: {
    Header,
  },
  name: 'register',
  data() {
    return {
      registerForm: {
        account: '',
        name: '',
        password: '',
        phone: '',
        character: '',
        factoryName: '',
        factoryDetail: '',
      },
      rules: {
        name: [{ required: true, message: '请输入姓名', trigger: 'blur' }],
        password: [{ required: true, message: '请输入密码', trigger: 'blur' }],
        account: [
          { required: true, message: '请输入账号', trigger: 'blur' },
        ],
        phone: [{ required: true, message: '请输入联系电话', trigger: 'blur' }],
        character: [
          { required: true, message: '请至少选择一个身份', trigger: 'change' },
        ],
        factoryName: [
          { required: true, message: '请输入工厂名称', trigger: 'blur' },
        ],
      },
    }
  },
  methods: {
    submitForm() {
      axios.post('user/register', this.registerForm).then((res) => {
        console.log(res)
        var m = res.data.message
        if (res.data.code == 200) {
          ElMessage.success({
            message: m,
            type: 'success',
          })
        } else {
          ElMessage.error(m)
        }
      })
    },
    resetForm(formName) {
      this.$refs[formName].resetFields()
    },
  },
}
</script>

<style lang="less" scoped>
.registry {
  position: relative;
  margin: auto;
  text-align: center;
  overflow: auto;
  background-color: #f9f9f9;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
}
.registerForm {
  width: 420px;
  position: relative;
  flex: 1 1 auto;
  margin-bottom: 100px;
}
.title {
  margin: 60px 0 60px 60px;
  font: 20px Helvetica, sans-serif;
  color: #000000;
  text-align: center;
  text-shadow: 0 2px 20px rgb(0 0 0 / 30%);
}
.registerBtn {
  width: 60%;
  background-color: #ffb000;
  border-radius: 10px;
  border: none !important;
  font-size: 10px;
}
.footer {
  position: relative;
  width: 100%;
  background-color: #fff;
  padding-top: 10px;
  padding-left: 20px;
}
.footerText {
  margin-top: 12px;
  text-align: center;
  font-size: 12px;
  color: #999;
}
</style>
